package com.jjh.users.service.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jjh.common.pojo.InfoEnum;
import com.jjh.common.util.ConstatFinalUtil;
import com.jjh.common.util.DateUtil;
import com.jjh.common.util.EncryptUtil;
import com.jjh.common.util.IoUtil;
import com.jjh.common.util.PageInfoUtil;
import com.jjh.users.dao.IACourseDao;
import com.jjh.users.dao.IASelectCourseDao;
import com.jjh.users.dao.IAStundentDao;
import com.jjh.users.dao.IAStundetFavDao;
import com.jjh.users.dao.IATeacherDao;
import com.jjh.users.pojo.ACourse;
import com.jjh.users.pojo.ASelectCourse;
import com.jjh.users.pojo.AStudent;
import com.jjh.users.pojo.AStudentEnum;
import com.jjh.users.pojo.AStudentFav;
import com.jjh.users.pojo.ATeacher;
import com.jjh.users.service.IUsersService;

/**
 * 用户service的实现类
 * @author MyJJh
 *
 */
@Service("usersService")
public class UsersServiceImpl implements IUsersService
{

	@Autowired
	private IAStundentDao studentDao ;
	@Autowired
	private IATeacherDao teacherDao ;
	@Autowired
	private IASelectCourseDao selectCourseDao ;
	@Autowired
	private IACourseDao courseDao ;
	@Autowired
	private IAStundetFavDao studentFavDao ;
	@Autowired
	private EncryptUtil encryptUtil ;
	@Autowired
	private DateUtil dateUtil ;
	@Autowired
	private IoUtil ioUtil ;
	
	@Override
	public JSONObject saveOneStudentService(AStudent student)
	{
		JSONObject resultJson = new JSONObject();
		
		Map<String,Object> condMap = new HashMap<String, Object>();
		condMap.clear();
		condMap.put("email", student.getEmail());
		/* 和数据库中的数据对比 */
		AStudent studentDb = this.findOneStudentService(condMap);
		if(studentDb != null)
		{
			/* 用户邮箱已经存在 */
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_EMAIL_EXISTS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.getString(resultJson.getString(InfoEnum.VAR_CODE.getInfo())));
			return resultJson ;
		}
		
		/* 密码加密 */
		student.setPassword(encryptUtil.encodeStr(student.getPassword()));
		/* 将状态设置为启用 */
		student.setStatus(AStudentEnum.STATUS_DISABLED.getStatus());
		
		student.setToalScore(50);
		student.setCreateTime(new Date());
		student.setUpdateTime(new Date());
		student.setLastLoginTime(new Date());
		
		/* 调用dao方法 */
		int res = this.studentDao.saveOneDao(student);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), student.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
		
	}

	@Override
	public JSONObject updateOneStudentService(AStudent student)
	{
		JSONObject resultJson = new JSONObject();
		
		student.setUpdateTime(new Date());
		
		/* 调用dao方法 */
		int res = this.studentDao.updateOneDao(student);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), student.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	}

	@Override
	public JSONObject deleteBatchStudentServcie(Map<String, Object> condMap)
	{
		JSONObject resultJson = new JSONObject();
		
		/* 调用dao方法 */
		int res = this.studentDao.deleteBatch(condMap);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	}

	@Override
	public AStudent findOneStudentService(Map<String, Object> condMap)
	{
		if(condMap != null && condMap.isEmpty())
		{
			ConstatFinalUtil.LOGGER.info("请输入查询的条件={}",condMap);
			return null ;
		}
		return this.studentDao.findOneDao(condMap);
	}

	@Override
	public List<AStudent> findCondListStudentService(PageInfoUtil pageInfoUtil,Map<String, Object> condMap)
	{
		/* 专门处理%的问题 */
		if(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) != null && !"".equalsIgnoreCase(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + ""))
		{
			condMap.put(InfoEnum.FINA_KEYWORD.getInfo(), "%" + condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + "%") ; 
		}
		
		/* 处理分页 */
		if(pageInfoUtil != null )
		{
			/* 分页 */
			Page<AStudent> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			/* 调用查询语句 */
			List<AStudent> list = this.studentDao.findCondListDao(condMap);
			/* 获取总条数 */
			long total = page.getTotal();
			pageInfoUtil.setTotalRecord(Long.valueOf(total).intValue());
			return list ; 
		}
		
		return this.studentDao.findCondListDao(condMap);
	}

	
	@Override
	public JSONObject saveOneTeacherService(ATeacher teacher)
	{
		JSONObject resultJson = new JSONObject();
		
		Map<String,Object> condMap = new HashMap<String, Object>();
		condMap.clear();
		condMap.put("email", teacher.getEmail());
		/* 和数据库中的数据对比 */
		ATeacher teacherDb = this.findOneTeacherService(condMap);
		if(teacherDb != null)
		{
			/* 用户邮箱已经存在 */
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_EMAIL_EXISTS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.getString(resultJson.getString(InfoEnum.VAR_CODE.getInfo())));
			return resultJson ;
		}
		
		/* 密码加密 */
		teacher.setPassword(encryptUtil.encodeStr(teacher.getPassword()));
		/* 将状态设置为启用 */
		teacher.setStatus(AStudentEnum.STATUS_DISABLED.getStatus());
		
		
		teacher.setCreateTime(new Date());
		teacher.setUpdateTime(new Date());
		teacher.setLastLoginTime(new Date());
		
		/* 调用dao方法 */
		int res = this.teacherDao.saveOneDao(teacher);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), teacher.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;		
	}

	@Override
	public JSONObject updateOneTeacherService(ATeacher teacher)
	{
		JSONObject resultJson = new JSONObject();
		
		teacher.setUpdateTime(new Date());
		
		/* 调用dao方法 */
		int res = this.teacherDao.updateOneDao(teacher);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), teacher.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	}

	@Override
	public JSONObject deleteBatchTeacherServcie(Map<String, Object> condMap)
	{
		JSONObject resultJson = new JSONObject();
		
		/* 调用dao方法 */
		int res = this.teacherDao.deleteBatch(condMap);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	}

	@Override
	public ATeacher findOneTeacherService(Map<String, Object> condMap)
	{
		if(condMap != null && condMap.isEmpty())
		{
			ConstatFinalUtil.LOGGER.info("请输入查询的条件={}",condMap);
			return null ;
		}
		return this.teacherDao.findOneDao(condMap);
	}

	@Override
	public List<ATeacher> findCondListTeacherService(PageInfoUtil pageInfoUtil,Map<String, Object> condMap)
	{
		/* 专门处理%的问题 */
		if(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) != null && !"".equalsIgnoreCase(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + ""))
		{
			condMap.put(InfoEnum.FINA_KEYWORD.getInfo(), "%" + condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + "%") ; 
		}
		
		/* 处理分页 */
		if(pageInfoUtil != null )
		{
			/* 分页 */
			Page<ATeacher> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			/* 调用查询语句 */
			List<ATeacher> list = this.teacherDao.findCondListDao(condMap);
			/* 获取总条数 */
			long total = page.getTotal();
			pageInfoUtil.setTotalRecord(Long.valueOf(total).intValue());
			return list ; 
		}
		
		return this.teacherDao.findCondListDao(condMap);
	}

	@Override
	public JSONObject saveOneSelectCourseService(ASelectCourse selectCourse)
	{
		JSONObject resultJson = new JSONObject();
		
		selectCourse.setCreateTime(new Date());
		selectCourse.setUpdateTime(new Date());
		selectCourse.setPubTime(new Date());
		
		/* 将状态设置为启用 */
		selectCourse.setStatus(AStudentEnum.STATUS_DISABLED.getStatus());
		
		/* 调用dao方法 */
		int res = this.selectCourseDao.saveOneDao(selectCourse);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), selectCourse.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;	
		
	}

	@Override
	public JSONObject updateOneSelectCourseService(ASelectCourse selectCourse)
	{

		JSONObject resultJson = new JSONObject();
		
		selectCourse.setUpdateTime(new Date());
		
		/* 调用dao方法 */
		int res = this.selectCourseDao.updateOneDao(selectCourse);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), selectCourse.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	
	}

	@Override
	public JSONObject deleteBatchSelectCourseServcie(Map<String, Object> condMap)
	{

		JSONObject resultJson = new JSONObject();
		
		/* 调用dao方法 */
		int res = this.selectCourseDao.deleteBatch(condMap);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	
	}

	@Override
	public ASelectCourse findOneSelectCourseService(Map<String, Object> condMap)
	{
		if(condMap != null && condMap.isEmpty())
		{
			ConstatFinalUtil.LOGGER.info("请输入查询的条件={}",condMap);
			return null ;
		}
		return this.selectCourseDao.findOneDao(condMap);
	}

	@Override
	public List<ASelectCourse> findCondListSelectCourseService(PageInfoUtil pageInfoUtil,Map<String, Object> condMap)
	{
		/* 专门处理%的问题 */
		if(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) != null && !"".equalsIgnoreCase(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + ""))
		{
			condMap.put(InfoEnum.FINA_KEYWORD.getInfo(), "%" + condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + "%") ; 
		}
		
		/* 处理分页 */
		if(pageInfoUtil != null )
		{
			/* 分页 */
			Page<ASelectCourse> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			/* 调用查询语句 */
			List<ASelectCourse> list = this.selectCourseDao.findCondListDao(condMap);
			/* 获取总条数 */
			long total = page.getTotal();
			pageInfoUtil.setTotalRecord(Long.valueOf(total).intValue());
			return list ; 
		}
		
		return this.selectCourseDao.findCondListDao(condMap);
	}

	@Override
	public JSONObject saveOneCourseService(ACourse course)
	{
		JSONObject resultJson = new JSONObject();
		
		course.setCreateTime(new Date());
		course.setUpdateTime(new Date());
		course.setPubTime(new Date());
		
		/* 将状态设置为启用 */
		course.setStatus(AStudentEnum.STATUS_DISABLED.getStatus());
		
		/* 调用dao方法 */
		int res = this.courseDao.saveOneDao(course);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), course.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;	
		
	}

	@Override
	public JSONObject updateOneCourseService(ACourse course)
	{

		JSONObject resultJson = new JSONObject();
		
		course.setUpdateTime(new Date());
		
		/* 调用dao方法 */
		int res = this.courseDao.updateOneDao(course);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), course.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	
	}

	@Override
	public JSONObject deleteBatchCourseServcie(Map<String, Object> condMap)
	{

		JSONObject resultJson = new JSONObject();
		
		/* 调用dao方法 */
		int res = this.courseDao.deleteBatch(condMap);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	
	}

	@Override
	public ACourse findOneCourseService(Map<String, Object> condMap)
	{
		if(condMap != null && condMap.isEmpty())
		{
			ConstatFinalUtil.LOGGER.info("请输入查询的条件={}",condMap);
			return null ;
		}
		return this.courseDao.findOneDao(condMap);
	}

	@Override
	public List<ACourse> findCondListCourseService(PageInfoUtil pageInfoUtil,Map<String, Object> condMap)
	{
		/* 专门处理%的问题 */
		if(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) != null && !"".equalsIgnoreCase(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + ""))
		{
			condMap.put(InfoEnum.FINA_KEYWORD.getInfo(), "%" + condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + "%") ; 
		}
		
		/* 处理分页 */
		if(pageInfoUtil != null )
		{
			/* 分页 */
			Page<ACourse> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			/* 调用查询语句 */
			List<ACourse> list = this.courseDao.findCondListDao(condMap);
			/* 获取总条数 */
			long total = page.getTotal();
			pageInfoUtil.setTotalRecord(Long.valueOf(total).intValue());
			return list ; 
		}
		
		return this.courseDao.findCondListDao(condMap);
	}

	@Override
	public JSONObject saveOneStudentFavService(AStudentFav studentFav)
	{
		JSONObject resultJson = new JSONObject();
		
		studentFav.setCreateTime(new Date());
		studentFav.setUpdateTime(new Date());
		studentFav.setPubTime(new Date());
		
		/* 将状态设置为启用 */
		studentFav.setStatus(AStudentEnum.STATUS_DISABLED.getStatus());
		
		/* 调用dao方法 */
		int res = this.studentFavDao.saveOneDao(studentFav);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), studentFav.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;	
		
	}

	@Override
	public JSONObject updateOneStudentFavService(AStudentFav studentFav)
	{

		JSONObject resultJson = new JSONObject();
		
		studentFav.setUpdateTime(new Date());
		
		/* 调用dao方法 */
		int res = this.studentFavDao.updateOneDao(studentFav);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_ID.getInfo(), studentFav.getId());
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	
	}

	@Override
	public JSONObject deleteBatchStudentFavServcie(Map<String, Object> condMap)
	{

		JSONObject resultJson = new JSONObject();
		
		/* 调用dao方法 */
		int res = this.studentFavDao.deleteBatch(condMap);
		
		if(res > 0 )
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_SUCCESS.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_SUCCESS.getCode())));
			
			JSONObject dataJson = new JSONObject();
			dataJson.put(InfoEnum.VAR_EFFECT.getInfo(), res);
			
			resultJson.put(InfoEnum.VAR_DATA.getInfo(), dataJson);
		}else
		{
			resultJson.put(InfoEnum.VAR_CODE.getInfo(), InfoEnum.INFO_FAILED.getCode());
			resultJson.put(InfoEnum.VAR_INFO.getInfo(), ConstatFinalUtil.INFO_JSON.get(String.valueOf(InfoEnum.INFO_FAILED.getCode())));
		}
		return resultJson;
	
	}

	@Override
	public AStudentFav findOneStudentFavService(Map<String, Object> condMap)
	{
		if(condMap != null && condMap.isEmpty())
		{
			ConstatFinalUtil.LOGGER.info("请输入查询的条件={}",condMap);
			return null ;
		}
		return this.studentFavDao.findOneDao(condMap);
	}

	@Override
	public List<AStudentFav> findCondListStudentFavService(PageInfoUtil pageInfoUtil,Map<String, Object> condMap)
	{
		/* 专门处理%的问题 */
		if(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) != null && !"".equalsIgnoreCase(condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + ""))
		{
			condMap.put(InfoEnum.FINA_KEYWORD.getInfo(), "%" + condMap.get(InfoEnum.FINA_KEYWORD.getInfo()) + "%") ; 
		}
		
		/* 处理分页 */
		if(pageInfoUtil != null )
		{
			/* 分页 */
			Page<AStudentFav> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			/* 调用查询语句 */
			List<AStudentFav> list = this.studentFavDao.findCondListDao(condMap);
			/* 获取总条数 */
			long total = page.getTotal();
			pageInfoUtil.setTotalRecord(Long.valueOf(total).intValue());
			return list ; 
		}
		
		return this.studentFavDao.findCondListDao(condMap);
	}

	@Override
	public JSONObject updateOneStudentService(AStudent student, Map<String, Object> paramMap)
	{
		/**
		 * 先更新数据库
		 * 在上传图片
		 */
		JSONObject resultJson = this.updateOneStudentService(student);
		/* 判断条件 */
		if(resultJson.getInteger("code") == InfoEnum.INFO_SUCCESS.getCode() && paramMap != null 
				&& !paramMap.isEmpty())
		{
			/* 上传的图片 */
			String souPath = student.getPhotoPath();
			
			/* 文件上传 */
			InputStream is = (InputStream) paramMap.get("is");
			String fileName = (String) paramMap.get("fileName");
			
			/* 拼装路径,完成上传 */
			/* 真实路径 */
			String truePath = ConstatFinalUtil.SYSTEM_JSON.getString("file.truePath") ; 
			/* 相对路径 */
			String relaPath = ConstatFinalUtil.SYSTEM_JSON.getString("rela.path");
			relaPath += "/students/" + this.dateUtil.dateToStr(new Date()) + "/" ;
			relaPath += UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf("."), fileName.length());
			
			/* 拼装真实的文件对象 */
			File trueFile = new File(truePath + relaPath);
			if(!trueFile.getParentFile().exists())
			{
				trueFile.getParentFile().mkdirs();
			}
			
			try
			{
				FileOutputStream fos = new FileOutputStream(trueFile);
				/* 拷贝流 */
				if(this.ioUtil.copyFile(is, fos))
				{
					/* 拷贝成功,赶紧把相对路径存储到数据中 */
					student.setPhotoPath(relaPath);
					/* 就是为了更新路径 */
					this.updateOneStudentService(student);
					/* 删除老照片 */
					File souFile = new File(truePath + souPath);
					if(!souFile.delete())
					{
						ConstatFinalUtil.LOGGER.error("==删除文件失败了=;" + trueFile.getAbsolutePath());
					}
				}else
				{
					ConstatFinalUtil.LOGGER.error("==上传文件失败了=;" + trueFile.getAbsolutePath());
				}
			} catch (Exception e)
			{
				ConstatFinalUtil.LOGGER.error("异常:{}",e);
			}
			
		}
		return resultJson;
	}
}
